package com.woniu.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.woniu.entity.CreProduct;
import com.woniu.entity.RepayEntity;
import com.woniu.service.CreditProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 产品管理控制
 */
@RestController
@Api("产品管理")
@RequestMapping("/credit/products")
public class CreditProductController extends BaseController {
    @Autowired
    private CreditProductService creditProductService;

    /*
     * 查询产品
     * */
    @GetMapping("/findAll")
    public TableDataInfo findAllProduct(CreProduct creProduct) {
        startPage();
        List<CreProduct> list = creditProductService.findAllProduct(creProduct);
        return getDataTable(list);
    }


    /**
     * 2022-9-20 19:45:14
     * Wei.SJ
     *
     * @return
     */
    @ApiOperation("公共页面产品查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品编号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "productName", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "escrow", value = "资金方", dataType = "String", dataTypeClass = String.class)
    })
    @RequestMapping("/anonymousFindAll")
    public AjaxResult anonymousFindAll(CreProduct creProduct) {
        List<CreProduct> list = creditProductService.anonymousFindAll(creProduct);
        return AjaxResult.success(list);
    }

    /*
     * 模糊查询
     * */
    @RequestMapping("/searchProduct")
    @ApiOperation("模糊查询获取产品详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "产品编号", dataType = "Integer", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "productName", value = "产品名称", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "escrow", value = "资金方", dataType = "String", dataTypeClass = String.class)
    })
    public TableDataInfo searchProduct(CreProduct creProduct) {
        startPage();
        List<CreProduct> list = creditProductService.searchProduct(creProduct);
        return getDataTable(list);
    }

    /*
     * 新增产品
     * */
    @PostMapping("/addproduct")
    public AjaxResult add(@RequestBody CreProduct creProduct) {
        return toAjax(creditProductService.addProducts(creProduct));
    }

    /*
     * 根据id查询产品详情
     * */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") int id) {
        return AjaxResult.success(creditProductService.findProductsById(id));
    }

    /*
     * 修改产品
     * */
    @PutMapping("/updateproduct")
    public AjaxResult edit(@RequestBody CreProduct creProduct) {
        return toAjax(creditProductService.updateProducts(creProduct));
    }

    /*
     * 删除产品
     * */
    @DeleteMapping("/{ids}")
    public AjaxResult delProducts(@PathVariable int[] ids) {
        return toAjax(creditProductService.delProducts(ids));
    }

    /*
     * 修改状态（逻辑删除）
     * */
    @PutMapping("/{id}/{enableStatus}")
    public AjaxResult editOneType(@PathVariable String enableStatus, @PathVariable Integer id) {
        return toAjax(creditProductService.editOneType(enableStatus, id));
    }

    /**
     * 购买时还款测算
     */
    @ApiOperation("购买时还款测算")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "loanAmount", value = "贷款金额", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "monthlyRate", value = "月利率", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "marginRate", value = "保证金利率", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "consultingFeeRate", value = "保证金利率", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "loanTerm", value = "保证金利率", dataType = "Double", dataTypeClass = Double.class),
            @ApiImplicitParam(name = "payTimes", value = "保证金利率", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "method", value = "保证金利率", dataType = "String", dataTypeClass = String.class)
    })
    @PostMapping("/getMoney")
    public AjaxResult getMoney(@RequestBody RepayEntity repayEntity) {
        return creditProductService.getMoney(repayEntity);
    }

}
